//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by 姜维克 on 16/5/20.
//  Copyright © 2016年 姜维克. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(imageName : String?=nil, title : String?, target: AnyObject?, action: Selector ){
        
            self.init()
    
            let rightBtn = UIButton()
        if let img = imageName{
            rightBtn.setImage(UIImage(named: img), forState: .Normal)
            
            rightBtn.setImage(UIImage(named: img+"_highlighted"), forState: .Highlighted)
        }
        //设置文字
        rightBtn.setTitle(title, forState: .Normal)
        
        //设置文字颜色
        rightBtn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        rightBtn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        //绑定点击事件
        rightBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
            
            rightBtn.sizeToFit()
            
    
            
            self.customView = rightBtn
        }
}